package com.jkl.controller.drIndex;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.jkl.entity.BaseResponseDTO;
import com.jkl.entity.drIndex.DrIndex;
import com.jkl.service.drIndex.inter.DrIndexServiceInterface;

import lombok.extern.slf4j.Slf4j;

@RestController
@RequestMapping("/jky/drIndex")
@Slf4j
public class DrIndexController {

	@Autowired
	private DrIndexServiceInterface DrIndexServiceInterface;

	@PostMapping("/getDrIndexList")
	public BaseResponseDTO getIndexList(DrIndex drIndex) {
		BaseResponseDTO returnData = new BaseResponseDTO();
		
		List<DrIndex> drIndexList = DrIndexServiceInterface.selectParamById(drIndex);
		JSONObject returnJson = new JSONObject();
		JSONArray drIndexArray = (JSONArray) JSONArray.toJSON(drIndexList);
		returnJson.put("drIndexList", drIndexArray);
		returnData.setReturnData(returnJson);
		return returnData;

	}

	@PostMapping("/drIndexjoinList")
	public PageInfo<DrIndex> drIndexjoinList(@RequestBody DrIndex drIndex) {
		return DrIndexServiceInterface.selectjoinId(drIndex);
	}
	
	@PostMapping("/saveDrIndex")
	public BaseResponseDTO save(@RequestBody DrIndex drIndex) {
		BaseResponseDTO returnData = new BaseResponseDTO();
		int drIndexInt = DrIndexServiceInterface.saveJoin(drIndex);
		if(drIndexInt!=0) {
			returnData.setResultMessage("添加成功");
		}else {
			returnData.setResultMessage("添加失败");
		}
		return returnData;
	}
	@PutMapping("/upDateDrIndex")
	public BaseResponseDTO upDate(@RequestBody DrIndex drIndex) {
		BaseResponseDTO returnData = new BaseResponseDTO();
		int drIndexInt = DrIndexServiceInterface.updateDrindex(drIndex);
		if(drIndexInt!=0) {
			returnData.setResultMessage("修改成功");
		}else {
			returnData.setResultMessage("修改失败");
		}
		
		return returnData;

	}
	
}
